package com.amumu.drama.common.constant;

import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Maps;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;

/**
 * @author sunzhuang
 * @date 2024/8/9 09:28
 * @slogan 天下风云出我辈, 一入代码岁月催
 * @desc 富友支付类型和系统支付类型映射
 */
@Getter
public enum FuiouPayTypeEnum {
    WeAppletPay(PayTypeEnum.WX_PAY, SourceTypeEnum.UNKNOWN, "WeAppletPay", "H5微信小程序"),
    AliPayJL(PayTypeEnum.ALI_PAY, SourceTypeEnum.UNKNOWN, "AliPayJL", "H5支付宝"),
    WeAppletPayH5(PayTypeEnum.WX_PAY, SourceTypeEnum.APP, "WeAppletPay", "H5微信小程序"),
    AliPayJLH5(PayTypeEnum.ALI_PAY, SourceTypeEnum.APP, "AliPayJL", "H5支付宝"),
    WeAppletPayPC(PayTypeEnum.WX_PAY, SourceTypeEnum.PC, "WeAppletPay", "H5微信小程序"),
    AliPayJLPC(PayTypeEnum.ALI_PAY, SourceTypeEnum.PC, "AliPayJL", "H5支付宝"),
    //    WeJsapiPay(PayTypeEnum.WX_PAY, "WeJsapiPay", "微信公众号"),
//    AliAppletPay(null, "AliAppletPay", "支付宝小程序"),
//    InstalPay(null, "InstalPay", "银联无卡分期"),
//    AppQuickPay(null, "AppQuickPay", "银行卡支付"),
//    YH0801030000(null, "0801030000", "农行卡支付"),
//    YH0803080000(null, "0803080000", "招行卡支付"),
//    YH0801040000(null, "0801040000", "中行卡支付"),
//    YH0801020000(null, "0801020000", "工商卡支付"),
//    YH0000000000(null, "0000000000", "云闪付支付"),
    /***
     * PC支付类型
     * 企业网银B2B
     * 个人网银=B2C
     * 快捷支付=QUICKPAY
     * 微信（间联）支付=SCANPAY
     * 微信（直连）支付=WXPAY
     * 支付宝（直连）支付=ALIPAY
     * 支付宝（间联）支付=ALIPAYJL
     * 云闪付/银联在线=UNIONPAY
     */
    ;


    /**
     * 支付类型
     */
    private PayTypeEnum payTypeEnum;

    private SourceTypeEnum sourceTypeEnum;

    private String payType;

    private String desc;

    FuiouPayTypeEnum(PayTypeEnum payTypeEnum, SourceTypeEnum sourceTypeEnum, String payType, String desc) {
        this.payTypeEnum = payTypeEnum;
        this.sourceTypeEnum = sourceTypeEnum;
        this.payType = payType;
        this.desc = desc;
    }

    private static Map<String, FuiouPayTypeEnum> UNINDEX = Maps.uniqueIndex(
            Arrays.asList(FuiouPayTypeEnum.values()),
            FuiouPayTypeEnum::getPayTypeUnionKey);

    private String getPayTypeUnionKey() {
        return getPayTypeUnionKey(payTypeEnum, sourceTypeEnum);
    }

    public static String getPayTypeUnionKey(PayTypeEnum payTypeEnum, SourceTypeEnum sourceTypeEnum) {
        return StrUtil.join("_", payTypeEnum.getType(), sourceTypeEnum.getType());
    }

    public static FuiouPayTypeEnum getByPayTypeEnum(PayTypeEnum payTypeEnum, SourceTypeEnum sourceTypeEnum) {
        return UNINDEX.get(getPayTypeByTypeEnum(payTypeEnum, sourceTypeEnum));
    }

    public static String getPayTypeByTypeEnum(PayTypeEnum payTypeEnum, SourceTypeEnum sourceTypeEnum) {
        FuiouPayTypeEnum fuiouPayTypeEnum = getByPayTypeEnum(payTypeEnum, sourceTypeEnum);
        if (fuiouPayTypeEnum == null) {
            return null;
        }
        return fuiouPayTypeEnum.getPayType();
    }
}
